package com.mku.parkingmanagement_service.controller;

import com.mku.parkingmanagement_service.entity.Stall;
import com.mku.parkingmanagement_service.entity.StallRes;
import com.mku.parkingmanagement_service.service.StallService;
import com.mku.parkingmanagement_service.vo.StallResVo;
import com.mku.parkingmanagement_service.vo.StallVo;
import com.mku.parkingmanagement_service.vo.comm.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @className: StallController
 * @author: Maoxx
 * @date: 2024/11/9 13:42
 * @Version: 1.0
 * @description:
 */

@RestController
@RequestMapping("/stall")
public class StallController {

    @Resource
    private StallService stallService;

    @GetMapping("/getStallsByPage")
    public ResultVO<Object> getStallsByPage(StallVo stallVo) {
        return stallService.getStallsByPage(stallVo);
    }

    @PostMapping("/addStall")
    public ResultVO<Object> addStall(@RequestBody Stall stall) {
        return stallService.addStall(stall);
    }

    @DeleteMapping("/deleteStall/{sid}")
    public ResultVO<Object> deleteStall(@PathVariable("sid") Integer sid) {
        return stallService.removeById(sid) ? ResultVO.success() : ResultVO.fail();
    }

    @PutMapping("/editStall")
    public ResultVO<Object> editStall(@RequestBody Stall stall) {
        return stallService.updateById(stall) ? ResultVO.success() : ResultVO.fail();
    }

    @GetMapping("/allList")
    public ResultVO<Object> allList(StallResVo stallResVo) {
        return ResultVO.success(stallService.getAllListStallRes(stallResVo));
    }

    @GetMapping("/orderStall")
    public ResultVO<Object> orderStall(Integer uid, Integer sid){
        return stallService.orderStall(uid,sid);
    }

    @GetMapping("/allRes")
    public ResultVO<Object> allStallRes(String person){
        return ResultVO.success(stallService.getAllStallRes(person));
    }

    @GetMapping("/allNoPay")
    public ResultVO<Object> allNoPay(String person){
        return ResultVO.success(stallService.getAllNoPay(person).stream().filter(r -> r.getOverTime()==null));
    }

    @PostMapping("/payMoneyPerson")
    public ResultVO<Object> payMoneyPerson(@RequestBody StallRes stallRes){
        return ResultVO.success(stallService.payMoneyPerson(stallRes));
    }

}
